import 'package:blog/Common/WebWidget.dart';
import 'package:flutter/material.dart';

import 'Common/BuildWidget.dart';

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  int _currentIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Youth Blog"),
        backgroundColor: Colors.black,
      ),
      bottomNavigationBar: _BottomNavigationBar(),
      floatingActionButton: FloatingActionButton(
        onPressed: null,
        child: Icon(Icons.volume_up),
      ),
      body: goPage(_currentIndex),
    );
  }

  _BottomNavigationBar() {
    return BottomNavigationBar(
        currentIndex: _currentIndex,
        onTap: (index) {
          setState(() {
            _currentIndex = index;
          });
        },
        unselectedItemColor: Colors.white38,
        selectedItemColor: Colors.white,
        //backgroundColor: Theme.of(context).primaryColor,
        backgroundColor: Colors.black,
        type: BottomNavigationBarType.fixed,
        items: [
          _bottomItem(Icons.home, "首页"),
          _bottomItem(Icons.whatshot, "列表"),
          _bottomItem(Icons.vpn_lock, "网站"),
          _bottomItem(Icons.account_circle, "我的"),
        ]);
  }

  _bottomItem(IconData icons, String label) {
    return BottomNavigationBarItem(
        icon: Icon(
          icons,
          color: Colors.white38,
          size: 24,
        ),
        activeIcon: Icon(
          icons,
          color: Colors.white,
          size: 24,
        ),
        label: label);
  }

  goPage(int _index) {
    if (_index == 2) {
      return Container(
//        width: 100,
//        height: 400,
        child: getWebView(),
      );
    } else {
      return BuildWidget();
    }
  }

  Widget getWebView() {
    return new WebWidget(URI: 'http://www.baidu.com/');
  }

  Future<Null> _handleRefresh() async {
    await Future.delayed(Duration(microseconds: 200));
    return null;
  }

  _item(String title, Color color) {
    return Container(
      alignment: Alignment.center,
      decoration: BoxDecoration(color: color),
      child: Text(
        title,
        style: TextStyle(fontSize: 22, color: Colors.white),
      ),
    );
  }
}
